$(function(){
	//初始化
	init();
	bindFun();
});
var contractId;
var result;
var policyRef;
var having="";
function init(){
	policyRef = sessionStorage.policyRef;
	contractId = sessionStorage.contractId;
	if(!contractId){
		contractId = getQueryString("contractId")
		sessionStorage.contractId=contractId;
	}
	if(!policyRef){
		policyRef  = getQueryString("policyRef");
		sessionStorage.policyRef=policyRef;
	}
	//初始NEWTOUCH数据
	var da={};
	da.contractId=contractId;
		padMarketing.ajaxNormal(
				"/pad_marketing/qualityCheck/initMyContent.action",
				da,
				function(data){
					if(data.flag=="01"){
						having="N";
					}else{
						having="Y";
						result = data.result;
						handle(result);
					}
					showLoadingPad("加载中");
					$("#pdfImg").attr("src","/pad_marketing/qualityCheck/showPdfPic.action?contractId="+contractId+"&flag=0"+"&type=NL3003"+"&policyRef="+policyRef).error(function(){
						alertMsg("网速较差,未生成pdf,请更换网络",0,function(){
							returnUrl();
						});
					});
					$("#pdfImg").attr("src","/pad_marketing/qualityCheck/showPdfPic.action?contractId="+contractId+"&flag=0"+"&type=NL3003"+"&policyRef="+policyRef).load(function(){
						hideLoadingPad();
						if(myScroll)
							myScroll.refresh();
					});
				}
		);
};
function bindFun(){
	$("#next").click(function(){
		if($(".check_yes").length==0){
			alertMsg("请选择照会操作");
			return;
		}
		//未处理
		if(having!="Y"){
			var obj={};
			obj.contractId=contractId;
			if($("#TB").attr("class")=="check_yes"){
				obj.tb="Y";
			}
			if($("#OTHER").attr("class")=="check_yes"){
				obj.other="Y";
			}
			if($("#ADD").attr("class")=="check_yes"){
				obj.add="Y";
			}
			padMarketing.ajaxNormal(
					"/pad_marketing/qualityCheck/insertMyContent.action",
					obj,
					function(data){
						if($("#TB").attr("class")=="check_yes" || $("#OTHER").attr("class")=="check_yes"){
							location.href="bodySign.action?contractId="+contractId+"&policyRef="+policyRef+"&url="+"noteDetailQC.action";
							return;
						}else{
							location.href="furtherInformation.action?contractId="+contractId+"&policyRef="+policyRef+"&url="+"noteDetailQC.action";
							return;
						}
					}
			);
		}else{
			//已处理
			if($("#TB").attr("class")=="check_yes disabled" || $("#OTHER").attr("class")=="check_yes disabled"){
				location.href="bodySign.action?contractId="+contractId+"&policyRef="+policyRef+"&url="+"noteDetailQC.action";
				return;
			}else{
				location.href="furtherInformation.action?contractId="+contractId+"&policyRef="+policyRef+"&url="+"noteDetailQC.action";
				return;
			}
			/*if($("#TB").attr("class")=="check_yes"){
				result.tb="Y";
			}else{
				result.tb="N";
			}
			if($("#OTHER").attr("class")=="check_yes"){
				result.other="Y";
			}else{
				result.other="N";
			}
			if($("#ADD").attr("class")=="check_yes"){
				result.add="Y";
			}else{
				result.add="N";
			}
			padMarketing.ajaxNormal(
					"/pad_marketing/qualityCheck/updateMyContent.action",
					result,
					function(data){
						if($("#TB").attr("class")=="check_yes" || $("#OTHER").attr("class")=="check_yes"){
							location.href="bodySign.action?contractId="+contractId+"&policyRef="+policyRef+"&url="+"noteDetailQC.action";
							return;
						}else{
							location.href="furtherInformation.action?contractId="+contractId+"&policyRef="+policyRef+"&url="+"noteDetailQC.action";
							return;
						}
					}
			);*/
		}
	});
};
//处理自己数据
function handle(data){
	if(data.allOk=="Y"){
		alertMsg("照会回复已提交",0,function(){
			returnUrl();
			return;
		});
	}
	if(data.add=="Y"){
		$("#ADD").attr("class","check_yes disabled");
	}else{
		$("#ADD").attr("class","check_no disabled");
	}
	if(data.tb=="Y"){
		$("#TB").attr("class","check_yes disabled");
	}else{
		$("#TB").attr("class","check_no disabled");
	}
	if(data.other=="Y"){
		$("#OTHER").attr("class","check_yes disabled");
	}else{
		$("#OTHER").attr("class","check_no disabled");
	}
	$("#ADD").off("click");
	$("#TB").off("click");
	$("#OTHER").off("click");
}
function returnUrl(){
	var url = getQueryString("url");
	if(url==null){
		location.href="/pad_marketing/index/index.action";
		return;
	}
	location.href=url;
}
